<template>
	<view>
		<nav-bar></nav-bar>
		
		<view class="" style="background: white;padding: 30px; ">
			<p style=" text-align: center;font-size: 20px;">{{news.newsname}}</p>
			<view class="" style="margin: 20px 0;">
				<span style="color: rgb(156,156,169);margin-right: 10px;">关键词:</span><span>{{news.guanjianci}}</span>
			</view>
			<view class="" style="margin: 20px 0;">
				<span style="color: rgb(156,156,169);margin-right: 10px;">资讯来源:</span><span>{{news.zixunlaiyuan}}</span>
			</view>
			<view class="" style="margin: 20px 0;">
				<span style="color: rgb(156,156,169);margin-right: 10px;">发布时间:</span><span>{{news.createTime.split(' ')[0]}}</span>
			</view>
			<p v-html="changeRich(news.content)"></p>
		</view>
	

	</view>
</template>

<script>
	export default {
		data() {
			return {
				id:"",
			news:{}
			}
		},
		onLoad(option) {
			this.id = option.id
			this.fetchNewsList()
			
		},
		methods: {
			   changeRich(str) {
			      if (!str) {
			        return '';
			      }
			      str = str.replace(/<img /g, '<img style="display:block;" ')
			      let newStr = str.replace(/<(img).*?(\/>|<\/img>)/g, function(mats) {
			        if (mats.indexOf('style') < 0) {
			          return mats.replace(/<\s*img/, '<img style="max-width:100%;height:auto;"');
			        } else {
			          return mats.replace(/style=("|')/, 'style=$1max-width:100%;height:auto;');
			        }
			      });
			      return newStr
			    },
			fetchNewsList(){
				var that = this
				this.$apiCall.request('get', `/news/${this.id }`, {}, {
					sucCb(data) {
						that.news = data.data
						console.log(that.newsinfo);
						
					}
				})
			}
		}
	}
</script>

<style>
.newsnamess{
/* border: 1px solid red; */
  color: rgb(254, 119, 67);
		width: 48%;
		overflow: hidden;  //超出隐藏
		white-space: nowrap; //不折行
		text-overflow: ellipsis; //溢出显示省略号
}
.createTimess{
	/* border: 1px solid red; */
			width: 48%;
			  color: rgb(254, 119, 67);
			overflow: hidden;  //超出隐藏
			white-space: nowrap; //不折行
			text-overflow: ellipsis; //溢出显示省略号
}
</style>
